#include <bits/stdc++.h>
using namespace std;
struct node{
    int l,r;
}c1[100010]={};
int p[100010]={},las,cnt,k,vi,ai,n,m,l1,v,t;
double tmp,eps=1e-6;
bool cmp(node n1,node n2){
    return n1.r<n2.r;
}
bool cmp1(node n1,node n2){
    return n1.l<n2.l;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n>>m>>l1>>v;
        k=0;
        while(n--){
            cin>>c1[++k].l>>vi>>ai;
            if(ai) tmp=(v+vi)*(v-vi)/2.0/ai+c1[k].l;
            if(vi<=v){
                if(ai<=0){
                    k--;
                    continue;
                }
                tmp+=1.0;
                c1[k].l=tmp;
                if(c1[k].l>l1){
                    k--;
                    continue;
                }
            }
            c1[k].r=l1;
            if(ai<0){
                if(abs(tmp-int(tmp))<eps) tmp-=1.0;
                c1[k].r=min(c1[k].r,int(tmp));
            }
        }
        sort(c1+1,c1+k+1,cmp);
        for(int i=1;i<=m;i++) cin>>p[i];
        cnt=0;
        las=0;
        for(int i=1;i<=k;i++){
            while(las<m&&p[las+1]<=c1[i].r) las++;
            if(las&&p[las]>=c1[i].l){
                c1[++cnt]=c1[i];
                c1[cnt].r=las;
            }
        }
        sort(c1+1,c1+cnt+1,cmp1);
        las=m+1;
        for(int i=cnt;i;i--){
            while(las>1&&p[las-1]>=c1[i].l) las--;
            c1[i].l=las;
        }
        sort(c1+1,c1+cnt+1,cmp);
        las=0;
        k=m;
        while(las<cnt){
            ai=c1[++las].r;
            k--;
            while(las<cnt&&c1[las+1].l<=ai) las++;
        }
        cout<<cnt<<" "<<k<<endl;
    }
    return 0;
}
